package site.assad.basicQuartzTest;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Author: Al-assad 余林颖
 * E-mail: yulinying_1994@outlook.com
 * Date: 2018/1/19 18:02
 * Description: 演示 ConTriggerRunner
 */
public class CronTriggerRunner {

    public static void main(String[] args) throws SchedulerException {

        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        JobDetail jobDetail = newJob(HelloJob.class)
                .withIdentity("job2","group1")
                .build();

        CronTrigger cronTriggerr = (CronTrigger)newTrigger()
                .withIdentity("trigger2","group1")
                .withSchedule(cronSchedule("0/5 * * * * ?"))  //指定 cron 表达式：每分钟从0s开始，间隔5s执行
                .build();

        scheduler.scheduleJob(jobDetail,cronTriggerr);
        scheduler.start();

    }
}
